package it.amicosmanettone.whatsimage;

import java.io.BufferedReader;
import java.io.InputStreamReader;

import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.DefaultHttpClient;

import android.util.Log;

public class HttpClientThread extends Thread {

	private String query = "";
	private String baseUrl = "";
	public static String threadOutput = "NO_OUTPUT";

	public HttpClientThread(String baseUrl, String query) {
		this.query = query;
		this.baseUrl = baseUrl;
	}

	@Override
	public void run() {
		try {
			String line = "";
			String resp = "";
			// TODO Auto-generated method stub
			HttpClient client = new DefaultHttpClient();
			HttpGet request = new HttpGet(baseUrl + query);
			HttpResponse response = client.execute(request);
			Log.v("JSON",String.valueOf(response.getStatusLine().getStatusCode()));
			BufferedReader rd = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
			while ((line = rd.readLine()) != null) {
				resp = resp + line;
			}// End while...
			threadOutput = resp;
			synchronized (this) {
				this.notify();
			}

		} catch (Exception e) {
			e.printStackTrace();

		}
	}

}
